package com.touni.designpattern.Iteratorpattern;

/**
 * @ClassName : NameResp
 * @Description :
 * @Author : lwq
 * @Date: 2020-11-21 10:40
 */
public class NameResp implements Container {

    private String[] strArr= {"orange","apple","fruit","banana"};

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements Iterator{

        private int index;

        @Override
        public boolean hasNext() {
            if (index < strArr.length){
                return true;
            }
            return false;
        }

        @Override
        public Object get() {
            if (this.hasNext()){
                return strArr[index++];
            }
            return null;
        }
    }
}
